package com.example.spring_mysql.interceptor

import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.springframework.stereotype.Component
import org.springframework.web.servlet.HandlerInterceptor
import java.util.*

@Component
class LoggingInterceptor : HandlerInterceptor {
    @Throws(Exception::class)
    override fun preHandle(request: HttpServletRequest, response: HttpServletResponse, handler: Any): Boolean {
//        println("======= 请求头 =======")
//        val headerNames = request.headerNames
//        while (headerNames.hasMoreElements()) {
//            val header = headerNames.nextElement()
//            val value = request.getHeader(header)
//            println("$header: $value")
//        }
//
//        println("======= Cookie =======")
//        val cookies = request.cookies
//        if (cookies != null) {
//            for (cookie in cookies) {
//                println(cookie.name + ": " + cookie.value)
//            }
//        } else {
//            println("无 Cookie")
//        }

        return true
    }
}
